package com.yan;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JdbcConn {


    protected Connection conns = null;

    protected PreparedStatement pst = null;

    protected ResultSet rs = null;

    public Connection getConnection(){
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conns = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8",
                    "root","123456");

        } catch (Exception e) {
            e.printStackTrace();
        }
        return conns;
    }

    public void closeConns(){
        try {
            if(rs!=null){
                rs.close();
            }

            if(pst!=null){
                pst.close();
            }

            if(conns!=null){
                conns.close();
            }

        } catch (Exception e) {
            // TODO: handle exception
        }
    }


}
